<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>基础知识</title>
</head>
<body>
    
</body>
</html>
<script>
    //面向过程编程
    //完全将所有的属性和方法都放在全局   很容易造成混乱
    // let name = '向军';
    // let grade = [
    //     {lesson:"js",score:99},
    //     {lesson:"mysql",score:85}
    // ];
    // //获取平均值
    
    // function average(grade,name){
    //     const total = grade.reduce((t,a) => {
    //         return t + a.score
    //     },0);
    //     return `${name}的平均成绩是${total/grade.length}分`;
    // }

    // console.log(average(grade,name));

    //**************************************************************
    //面向对象编程
    // let User = {
    //     name : "向军",
    //     grade : [
    //         {lesson:"js",score:99},
    //         {lesson:"mysql",score:85}
    //     ],
    //     average:function(){
    //         const total = this.grade.reduce((t,a) => {
    //             return t+a.score;
    //         },0);
    //         console.log(total)
    //         return `${this.name}的平均成绩是${total/this.grade.length}分`;
    //     }
    // };

    // console.log(User.average());

</script>